#  Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
#  Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
#  Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
#  Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
#  Vestibulum commodo. Ut rhoncus gravida arcu.
#  Only supports NVIDIA GEFORCE RTX series graphics cards
#  Xiaosi Artificial Intelligence Copyright reserved/No tampering or code theft allowed
#  Powered by XiaoSi Artificial Intelligence on Sir Shao | Sir Wu | Sir Li
#  Thank you again to the optimization team
import json
import os
import sys
import webbrowser
from concurrent.futures import ThreadPoolExecutor
import time
from inspect import unwrap
import numpy as np
import requests
import subprocess
from jinja2.utils import url_quote
RTX = "----- NVIDIA GEFORCE RTX 驱动下载 ------ [ 是否驱动需要更新或下载 (y/n) ]"
list = input(RTX)
if list =='y':
    url = 'https://www.nvidia.cn/geforce/drivers/'
    webbrowser.open(url)
    sys.exit()
if list == 'n':
    os.system('echo.')
# 运行 nvidia-smi 命令
result = subprocess.run(['nvidia-smi'], capture_output=True, text=True)

# 检查命令是否成功执行
if result.returncode == 0:
    print("+----------| NVIDIA显卡已安装 |----------+")
else:
    print("+----------|** NVIDIA显卡未安装 **|----------+")

# 优化算法
def optimized_algorithm(array):
    return np.sum(array)  # 使用NumPy进行快速求和

# 使用多线程
def run_concurrently(functions, args):
    with ThreadPoolExecutor() as executor:
        results = list(executor.map(lambda f: f(*args), functions))
    return results

print('=*=*=*=*=*= 欢迎使用 Xiao Si Artificial Intelligence NEXT =*=*=*=*=*=')
print('=*=*=*=*=*= Welcome to Xiao Si Artificial Intelligence NEXT =*=*=*=*=*=')
print('Powered by Xiao Si Artificial Intelligence Kernel 2.0.3.10 ')
XS = "| 0.官方 | 1.退出 |" " 2.更新 |" " 3.手册咨询 | 4.开始使用 | 5.开发者抢先版下载 | " "请做出你的选择 /=*=*=*=*>"

key = input(XS)
if key == "0":
    url = "https://gitee.com/dirde12078904"
    webbrowser.open(url)
    sys.exit()
if key == "1":
    sys.exit()
if key == '2':
    url = "https://gitee.com/dirde12078904/xiao-si/releases"
    # 打开默认浏览器并显示指定的URL
    webbrowser.open(url)
    sys.exit()
if key == '3':
    url = "https://gitee.com/dirde12078904/technical-white-paper-sharing"
    # 打开默认浏览器并显示指定的URL
    webbrowser.open(url)
    sys.exit()
if key =='5':
    uel = "https://gitee.com/dirde12078904/Xiaosi-Artificial-Intelligence-Developer-Conference/releases"
    webbrowser.open(uel)
    print('也欢迎来加入项目')
    time.sleep(10)
    sys.exit()
if key == '4':
    os.system('echo.')
print('***************************************************************************************************')
print(
    '\033[1;31;43m|     ::::-++++++++++++-         .::::-++++++++++++:      .:::-==+++************++++=          '
    '|\033[0m')
print(
    '\033[1;31;43m|      :----+***********=       .----=*********+*+.    .:---=++***++++++++++++++++**+          '
    '|\033[0m')
print(
    '\033[1;31;43m|       .----=+*++++++++*+.    :----=*+++++++++*-     -----+**++++++++***********++*=          '
    '|\033[0m')
print(
    '\033[1;31;43m|         :----+*++++++++*+:  :----+*++++++++*+:     -----+*++++++++*++========+++**=          '
    '|\033[0m')
print(
    '\033[1;31;43m|          :----=*++++++++**-:----+*++++++++*=.     .-----*++++++++*-             ...          '
    '|\033[0m')
print(
    '\033[1;31;43m|           .----=+*++++++++*+--=+*+++++++**-       :----=*+++++++*+                           '
    '|\033[0m')
print(
    '\033[1;31;43m|             :----+*++++++++*+=*++++++++*+:        :----=*+++++++++-                          '
    '|\033[0m')
print(
    '\033[1;31;43m|              :----=*++++++++**++++++++*=          .-----+*++++++++*++=-:..                   '
    '|\033[0m')
print(
    '\033[1;31;43m|               .----=+*+++++++++++++++*-            :----=+*+++++++++******++=-:.             '
    '|\033[0m')
print(
    '\033[1;31;43m|                 :----+*++++++++++++++.              .:----++***++++++++++++****++-           '
    '|\033[0m')
print(
    '\033[1;31;43m|                .----=++++++++++++++++-                 .:::-==++*******+++++++++**+:         '
    '|\033[0m')
print(
    '\033[1;31;43m|               :----+*++++++++++++++++*+.                     ..::-===+++**++++++++**.        '
    '|\033[0m')
print(
    '\033[1;31;43m|             .----=+*++++++++**++++++++**-                          .:---=+*++++++++*-        '
    '|\033[0m')
print(
    '\033[1;31;43m|            :----=**++++++++*==+*++++++++*=                          .-----+*+++++++*=        '
    '|\033[0m')
print(
    '\033[1;31;43m|           :----+*++++++++*+=---+*++++++++*+.                        .-----+*+++++++*=        '
    '|\033[0m')
print(
    '\033[1;31;43m|         .----=+*++++++++*=.:----+*++++++++**-     ::...-=-:...     .----=+*++++++++*:        '
    '|\033[0m')
print(
    '\033[1;31;43m|        :----=*+++++++++*=   .----=*+++++++++*=    -----+******++++++++++**++++++++*+         '
    '|\033[0m')
print(
    '\033[1;31;43m|       :----+*++++++++**:     .----=+*++++++++*+:  -----++++++++***+++*++++++++++**=          '
    '|\033[0m')
print(
    '\033[1;31;43m|    .----=**+******+*+.        -----+*+******+**- -----+***+++++++++++++++*****+=:            '
    '|\033[0m')
print(
    '\033[1;31;43m|    :-::-=+++++++++++=           ::::-=++++++++++*+:::::=++++++**********++++=-:              '
    '|\033[0m')
print(
    '\033[1;31;43m*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- Xiao_Si_AI_NEXT '
    '-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-\033[0m')
print(
    '\033[1;31;43m|----------------------------------Xiao_Si_AI_NEXT Developer Beta '
    'Version---------------------|\033[0m')
print(
    '\033[1;31;40m=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=- 你好,我是 Xiao Si Artificial Intelligence NEXT '
    '=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-\033[0m')
print('\033[1;36m     - > Xiaosi Artificial Intelligence Program < -\033[0m')
print('\033[1;31m            -- 版本所有权 -- 更新查看网址 -- \033[0m')
print('\033[1;31m = > https://gitee.com/dirde12078904/xiao-si/releases < =\033[0m')
API_KEY = '2iU0QJiVJBQqCKOLW5Jf8aS9'
SECRET_KEY = 'Aqg401HImuqRaprlpctYDLO1TnkClH6c'
def main():
    print('\033[1;36m作为你的智能伙伴，我既能写文案、想点子，又能陪你聊天、答疑解惑\033[0m')
    print('         请输入你想问的问题(注：什么问题不问,直接回车及为退出)')
    print("=-=-=-=-=-=-=-=-=-=-=-=-= 说 出 你 的 问 题 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
    xiao_si = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token=" + get_access_token ()
    while 1:
        s = input()
        # 注意message必须是奇数条
        payload = json.dumps({
            "messages": [
                {
                    "role": "user",
                    "content": s
                }
            ]
        })
        headers = {
            'Content-Type': 'application/json'
        }

        res = requests.request("POST", xiao_si, headers=headers, data=payload).json()
        print("\033[33mXiao Si AI NEXT\033[0m")
        print(res['result'])
        print('The content is generated by AI and cannot be guaranteed to be true and accurate. It is for reference '
              'only')
        print('\033[31;5m  = | = | = | = | = | = | = | = > 内容由AI生成，无法确保真实准确，仅供参考 < = | = | = | = | = | = | = | = | '
              '=\033[0m\r\n')
        print('请输入你想问的问题(注：如果您没问题了,可直接回车,视为退出)')
        print('Please enter the question you want to ask (note: If you have no further questions, you can simply '
              'enter the key, which will be considered as exiting)')
        print("=+=+=+=++=+=+=++=+=+=+说出你的问题+=+=+=+=+=+=+=+=+=++=+=+=+=")


def get_access_token():
    xiao_si = "https://aip.baidubce.com/oauth/2.0/token"
    params = {"grant_type": "client_credentials", "client_id": API_KEY, "client_secret": SECRET_KEY}
    return str(requests.post(xiao_si, params=params).json().get("access_token"))


if __name__ == '__main__':
    main()